package com.zr.serviceimpl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zr.dao.SearchQuestionsDao;
import com.zr.model.Cquestion;
import com.zr.service.SearchQuestionsService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

@Service("searchQuestionsService")
public class SearchQuestionsServiceImpl implements SearchQuestionsService{

	@Resource SearchQuestionsDao<Cquestion> searchQuestionsDao;
	
	
	@Override
	public JSONArray findAllQuestions() {
		JSONArray js = new JSONArray();
		List<Cquestion> qs = new ArrayList<Cquestion>();
		qs = searchQuestionsDao.getAllQuestions();
		for (Cquestion q : qs) {
			JSONObject j = new JSONObject();
			j.put("qid", q.getQid());
			j.put("question", q.getQuestion());
			js.add(j);
		}
		return js;
	}

}
